package com.ys.controller.web.finance;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.config.MenuId;
import com.ys.config.MyConfig;
import com.ys.entity.finance.TcwDepositPlatformAccount;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.W;

@Controller
@RequestMapping("/web/finance/tcwDepositPlatformAccount")
public class WebTcwDepositPlatformAccountController {


	@Autowired
	private CommonApiService<TcwDepositPlatformAccount> commonApiService;

	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model) throws Exception {

		TcwDepositPlatformAccount entity = new TcwDepositPlatformAccount();
		Map<String, Object> extraParam = new HashMap<String, Object>();
		//关联数据
		entity.setCode(commonApiService.getCommonNextUkey(MenuId.TCW_DepositPlatformAccount, "Code"))
				.setStatus(1);
		String aa = commonApiService.toAdd(model, entity, MenuId.TCW_DepositPlatformAccount, extraParam, null);
        
        if ("test".equals(MyConfig.getActive()) || "pro".equals(MyConfig.getActive())) {
			return "finance/tcwDepositPlatformAccount/tcwDepositAccountPlatformAdd";
		} else {
			return aa;
		}
	}


	/*
	 * 编辑
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model, String code) throws Exception {
		if (code == null){
			return W.error(model, "收款平台编码不能为空");
		}
		
		Map<String, Object> extraParam = new TcwDepositPlatformAccount().setCode(code)
				.addLeftJoin("TCW_DepositPlatform B ON B.Code = A.DepositPlatformCode")
				.addLeftJoin("TB_CompanyInfo C ON C.Vid = B.CompanyVid")
				.addLeftJoin("TP_AmazonRegion D ON D.Code = A.RegionCode")
				.addLeftJoin("TP_AmazonShopExchangeRate E ON E.Code = A.CurrencyCode")
				.addLeftJoin("THR_OperateCompanyApply F ON F.Vgsbm = A.Vgsbm ")
				.addLeftJoin("TB_Platform G ON G.Code = D.PlatformCode")
				.addField("B.Name AS depositPlatformName")
				.addField("B.Code AS depositPlatformCode")
				.addField("B.PlatformName AS name")
				.addField("B.Mid AS depositPlatformMid")
				.addField("C.Vname AS companyVname")
				.addField("D.Code AS regionCode")
				.addField("G.Name AS platformName")
				.addField("G.Code AS platformCode")
				.addField("D.Name AS regionNamejc")
				.addField("E.Name AS currencyName")
				.addField("E.id AS currency")
				.addField("F.Vgsbm AS vgsbm")
				.addField("F.Vgsjc AS vgsjc")
				.queryFirstMap();

		String aa = commonApiService.toEdit(model, Long.valueOf(extraParam.get("id").toString()), new TcwDepositPlatformAccount(), MenuId.TCW_DepositPlatformAccount, extraParam, null);
        
        if ("test".equals(MyConfig.getActive()) || "pro".equals(MyConfig.getActive())) {
    		return "finance/tcwDepositPlatformAccount/tcwDepositAccountPlatformEdit";
		} else {
			return aa;
		}
	}
}




